/**
 * Copyright (c) 2007/2008 by Rowan Rodrik van der Molen
 *
 * This file is part of readline-trainer.
 *
 * readline-trainer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * at your option) any later version.
 *
 * readline-trainer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with readline-trainer.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef PARSER_H
#define PARSER_H

//#define DEBUG_PARSER

#include "lessons.h"


/**
 * This is a list of possible contexts that are useful for the parser to know.
 */
enum trrl_parser_context
{
    TRRL_NOWHERE,               // Not started yet
    TRRL_INSIDE_LESSON_LIST,    // Inside <lessons>
    TRRL_INSIDE_LESSON,         // Inside <lesson>
    TRRL_INSIDE_LESSON_TITLE,   // Inside <title>
    TRRL_INSIDE_EXERCISE,       // Inside <exercise>
    TRRL_INSIDE_INSTRUCTION,    // Inside <instruction>
    TRRL_INSIDE_HINT            // Inside <hint>
};


/**
 * What the parser is doing and where it's at.
 */
typedef struct trrl_parser_state
{
    unsigned int lesson_count;
    trrl_lesson_ptr first_lesson;
    trrl_lesson_ptr last_lesson;
    trrl_exercise_ptr first_exercise;  // First exercise _within the current lesson_
    trrl_exercise_ptr last_exercise;   // Last exercise _within the current lesson_
    enum trrl_parser_context context;
} trrl_parser_state;
typedef trrl_parser_state* trrl_parser_state_ptr;


/**
 * Zero and NULLify all the fields in the trrl_parser_state structure pointed to by the argument.
 */
void
trrl_clear_parser_state(trrl_parser_state_ptr);


/**
 * Parse a given <lessons> XML file into a trrl_lesson structure.
 *
 * Returns a pointer to the new structure.
 */
trrl_lesson_ptr
trrl_parse_lessons_file(char* filename);


#endif
// vim: expandtab shiftwidth=4 tabstop=4:
